<!doctype html>
<html>

<head>
	<title></title>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
	<link rel="stylesheet" href="../res/css/weui.css" />
	<link rel="stylesheet" href="../res/css/weuix.css" />
	<link rel="stylesheet" href="../res/css/common.css" />
	<link rel="stylesheet" href="../res/css/swiper.css">
	<script src="../res/js/swiper.js"></script>
	<script src="../res/js/zepto.min.js"></script>
	<script src="../res/js/zepto.weui.js"></script>
	<!-- <script src="../res/js/picker.js"></script> -->
	<script src="../res/js/common.js?v=5"></script>
	<script src="../res/js/socket.js"></script>

	<style>
		.btn {
			margin-top: 5px;
			width: 20%;
			height: 30px;
			line-height: 30px;
			text-align: center;
			border-radius: 5px;
			cursor: pointer;
		}

		.active {
			background-color: #1189FF;
			color: white;
		}
	</style>
	<script>
		var patientList;
		var inquiry_curr_date, jobListValue = [],
			jobListName = [];
		var jobName = '',
			jobCode = '',
			h5_token = '';
		var patientName = "",
			doctor_name = "";
		var mySwiper, showPic;
		// var index = 0;
		var flag = true;
		var ossdata = {}; //oss信息
		//就诊人列表信息
		var patientInfoList = []
		//swiper选择num
		var num = -1;
		//图片数组
		var picDataList = [],
			picNum = 1; //记录上传图片按钮数量

		var agreementType = 0; //当前打开的用户协议类型

		const agreements = {
			titleList: [],
			idList: [2, 6]
		}

		let myPager;	//强制阅读

		//建立webscoket连接
		// 初始化webscoket
		// function initWebSocket() {
		// 	// 连接socket 重构的聊天要用到socket
		// 	var token = null;
		// 	var userJson = localStorage.getItem('DSXBuserJson');
		// 	user_id = strToJson(userJson).id
		// 	if (userJson) {
		// 		token = strToJson(userJson).h5Token
		// 	}
		// 	wsConnection.initWebSocket('wss://hospital-test.yixianmedical.com/websocket', token);
		// }
		// initWebSocket()


		//请求OSS参数
		function newOssPolicy() {
			newAjaxPost("/h5/oss/ossPolicy", {}, newOssPolicyOk);
		}

		function newOssPolicyOk(jsonInfo) {
			if (jsonInfo.code == 1) {
				ossdata = jsonInfo.data
				// console.log(ossdata);
			}
		}

		//是否药物过敏
		function setDrugAllergy(is_drug_allergy) {
			//是否药物过敏 .0否 1是
			if (is_drug_allergy == undefined) {
				$('#ddl_drug_allergy').val(0)
			}
			if (is_drug_allergy == '1')
				$('#div_allergy_details').show();
			else
				$('#div_allergy_details').hide();
		}
		//是否
		function pastMedicalHistory(is_drug_allergy) {
			//是否有过过往病史 .0否 1是
			if (is_drug_allergy == undefined) {
				$('#ddl_medical_history').val(0)
			}
			if (is_drug_allergy == '1')
				$('#div_medical_history').show();
			else
				$('#div_medical_history').hide();
		}

		function doSavePat() {
			if (num == -1) {
				msgInfo('请先选择就诊人');
				return
			}
			// !TESTING && 
			if(isUndefinedAndEmpty($("#firstInquiryHos").val())) {
				msgInfo('请输入初诊医院')
				return
			}
			// !TESTING && 
			if(isUndefinedAndEmpty($("#inquiryTime").val())) {
				msgInfo('请选择初诊时间')
				return
			}
			
			let timeVal = $("#inquiryTime").val()
			let useSlash = /\//.test(new Date().toLocaleDateString())
			useSlash ? timeVal = timeVal.replace(/\-/g, '/') : null

			let selectedTime = new Date(timeVal).getTime()
			let nowTime = new Date().getTime()
			console.log(timeVal)
			if(selectedTime > nowTime){
				msgInfo('初诊时间不能晚于当前时间')
				return
			}

			// !TESTING && 
			if(picNum < 2){
				msgInfo('请至少上传一张初诊相关的图片')
				return
			}
			if (!document.getElementById('weuiAgree').checked) {
				msgInfo(`请查阅${agreements.titleList.join('、')}并勾选我已详细阅读`);
				return;
			}
			if(isChengDu && patientInfoList[num].patientAge <= 14){
				msgInfo('暂不支持对14岁及14岁以下的患者进行问诊')
				return
			}
			
			let patientInfo = patientInfoList[num];
			var paramJson = {
				"inquiryPatientId": patientInfo.id,
				"doctorId": parseInt(getQst('doctor_id')), //医生id
				"inquiryType": getQst('log_type'), //记录类型 1视频问诊 2图文问诊 3家庭医生问诊 4复诊  (3,4默认图文问诊)
				"medicalRecord": picDataList.join(","), //上传的图片字符串
				"primaryHospital": $("#firstInquiryHos").val(), //初诊医院
				"primaryTime": $("#inquiryTime").val()		//初诊时间
			}
			// console.log(paramJson);
			newAjaxPost("/h5/inquiryPatientInfo/addInquiryPatientInfo", paramJson, doSavePatSuccess);
		}

		function doSavePatSuccess(jsonInfo) {
			// console.log(jsonInfo);

			var inquiryType = getQst('log_type')
			if (jsonInfo.code == '1') {
				var logId = jsonInfo.data.logId
				var data = jsonInfo.data;
				var tvflag = getQst("tvflag");
				if (isUndefinedAndEmpty(tvflag)) {
					tvflag = 0
				}
				console.log(inquiryType);
				if (inquiryType == 1 || inquiryType == 2) {
					//冻结问诊费账单
					newAjaxPost("/h5/wxpay/frozenOrder", {
						"logId": logId
					}, frozenOrderOK);

					function frozenOrderOK(jsonInfo) {
						if (jsonInfo.code == 1) {
							// window.location.replace('inquiry_chatwait.htm?isChatWait=1&log_id=' + data.logId + '&doctor_id=' + getQst('doctor_id') +
							// 	'&doctor_imid=' + data.doctorImId + '&log_type=' + inquiryType + '&tvflag=' + tvflag);
							window.location.replace('chat.htm?isChatWait=1&log_id=' + data.logId + '&doctor_id=' + getQst(
									'doctor_id') +
								'&doctor_imid=' + data.doctorImId + '&log_type=' + inquiryType + '&tvflag=' + tvflag);
						}
					}
				} else {
					/*
						logId 网络医院问诊id
						inquiryPatientId 问诊人信息id
						patientIM 用户Im
						doctor_id 医生id
						doctorImId 医生im
					*/

					function formatDate(date, format) {
						if (format === undefined) {
							format = 'YY-MM-DD hh:mm:ss';
						}

						var year = date.getFullYear(),
							month = date.getMonth() + 1, //月份是从0开始的
							day = date.getDate(),
							hour = date.getHours(),
							min = date.getMinutes(),
							sec = date.getSeconds();
						var preArr = Array.apply(null, Array(10)).map(function (elem, index) {
							return '0' + index;
						});
						var newTime = format.replace(/YY/g, year)
							.replace(/MM/g, preArr[month] || month)
							.replace(/DD/g, preArr[day] || day)
							.replace(/hh/g, preArr[hour] || hour)
							.replace(/mm/g, preArr[min] || min)
							.replace(/ss/g, preArr[sec] || sec);

						return newTime;
					}

					var time = formatDate(new Date());
					wsConnection.send(5, {
						logId: data.logId, // 本次问诊的id
						doctorImId: data.doctorImId // 医生id
					});
					console.log(data.userIm, doctor_name, data.logId);
					wsConnection.send(3, {
						'msgText': "请描述您的症状【感受最明显的一个或者数个症状或(体征)】 和患病时长【起病至就诊的时间】", // 信息体
						'friendId': data.userIm, // 用户imID
						'inquiryLogId': data.logId, //问诊id
						'msgusername': doctor_name,
						'msgType': 6,
						'msgDate': time
					});
					setTimeout(function () {
						wsConnection.send(3, {
							'msgText': "回答完毕记得点击下方【已完成】，我们会将您的信息发送给医生哦！", // 信息体
							'friendId': data.userIm, // 用户imID
							'inquiryLogId': data.logId, //问诊id
							'msgusername': doctor_name,
							'msgType': 6,
							'msgDate': time
						});
						// goPage('inquiry_chat.htm?isChatWait=0&log_id=' + data.logId + '&doctor_id=' + getQst(
						// 		'doctor_id') +
						// 	'&doctor_imid=' +
						// 	data.doctorImId + '&log_type=' + inquiryType + '&inquirypatientId=' +
						// 	data.inquiryPatientId + '&patientIM=' + data.userIm + '&tvflag=' + tvflag);
						window.location.replace('chat.htm?isChatWait=0&log_id=' + data.logId + '&doctor_id=' + getQst(
								'doctor_id') +
							'&doctor_imid=' +
							data.doctorImId + '&log_type=' + inquiryType + '&inquirypatientId=' +
							data.inquiryPatientId + '&patientIM=' + data.userIm + '&tvflag=' + tvflag);
					}, 500)
				}
			} else {
				if (jsonInfo.msg == "用户已在问诊中") {
					$(".backgrounds").show()
					$(".endInquiryInfo").show()
				} else {
					msgInfo(jsonInfo.msg);
				}
			}

		}

		function range(r, a, N) {
			var i, o, s = [],
				e = N || 1,
				f = !1;
			if (isNaN(r) || isNaN(a) ? isNaN(r) && isNaN(a) ? (f = !0, i = r.charCodeAt(0), o = a.charCodeAt(0)) : (i = isNaN(
					r) ? 0 : r, o = isNaN(a) ? 0 : a) : (i = r, o = a), !(i > o))
				for (; i <= o;) s.push(f ? String.fromCharCode(i) : i), i += e;
			else
				for (; i >= o;) s.push(f ? String.fromCharCode(i) : i), i -= e;
			return s
		}

		function showAgreeInfo(type) {
			doGetAgree(type);
			$("#divAgreeInfo").popup(); //打开
		}

		function doGetAgree(id) {
			if (agreementType != id) {
				let params = {id}
				newAjaxPost("/h5/utilInitData/getAgreement", params, doGetAgreeOk);
				agreementType = id
			}
			return false;
		}

		function doGetAgreeOk(jsonInfo) {
			if (jsonInfo.code == 1) {
				$("#argeeTitle").text(jsonInfo.data.initName);
				$("#argeeContent").html(jsonInfo.data.initKey.replace(/。/g, '。<br>'));
			}
		}

		function checkWxAndIos() {
			var u = navigator.userAgent;
			var ua = navigator.userAgent.toLowerCase();
			var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
			// ----------------------4.10
			if (isIOS) {
				$('#btnBack').css('display', 'none');
			}
			// -------------------
			if (isIOS && ua.match(/MicroMessenger/i) == "micromessenger")
				return true;
			else
				return false;
		}

		function iosGoBrowser() {
			var isWxAndIos = checkWxAndIos();
			if (isWxAndIos && getQst("log_type") == '1') {
				var winHeight = $(window).height();
				$(".weixin-tip").css("height", winHeight);
				$(".weixin-tip").show();
				setTimeout(function () {
					$.alert({
						title: '温馨提示',
						text: '当您已完成问诊时，请点击确认前往我的处方查看',
						onOK: function () {
							//点击确认
							goPage('recipe_list.htm');
						}
					});
				}, 30000);
			} else {
				var strOrgId, strOpenId, strTvflag;
				strOrgId = getQst("orgid");
				strOpenId = getQst("openid");
				strTvflag = getQst('tvflag');
				// ---------------------------------4.21
				// if (!isSpace(strOrgId) && !isSpace(strOpenId) && !isSpace(h5_token)) {
				if (!isSpace(strOrgId) && !isSpace(strOpenId) && !isLogin()) {
					if (isUndefinedAndEmpty(strTvflag)) {
						goPage('inquiry_go.htm?go_type=4&orgid=' + strOrgId + '&openid=' + strOpenId + '&log_type=' + getQst(
								"log_type") + '&doctor_id=' + getQst("doctor_id") + "&rand=" +
							Math.random());
					} else {
						goPage('inquiry_go.htm?go_type=5&orgid=' + strOrgId + '&openid=' + strOpenId + '&log_type=' + getQst(
								"log_type") + '&doctor_id=' + getQst("doctor_id") + "&rand=" +
							Math.random());
					}
				}
				// ---------------------------------
			}
		}
		//swiper设置
		function swiper() {
			mySwiper = new Swiper('#banner .swiper-container', {
				loop: false,
				autoplay: false,
				pagination: {
					el: '#banner .swiper-pagination',
				},
				slidesPerView: 'auto',
				spaceBetween: 10,
				observer: true, //修改swiper自己或子元素时，自动初始化swiper
				observeParents: true, //修改swiper的父元素时，自动初始化swiper
				on: {
					click: function () {
						num = this.clickedIndex
						$('.swiper-slide').eq(num).addClass("active")
						$('.swiper-slide').eq(num).siblings().removeClass("active")
						$("#btnInquiry").text(`发起问诊(就诊人${patientInfoList[num].patientName})`)
					},
				},
			})
			showPic = new Swiper('.showPic .swiper-container', {
				loop: false,
				autoplay: false,
				pagination: {
					el: '.showPic .swiper-pagination',
				},
				slidesPerView: 'auto',
				observer: true, //修改swiper自己或子元素时，自动初始化swiper
				observeParents: true, //修改swiper的父元素时，自动初始化swiper
				on: {
					click: function () {
						$('.showPic').hide();
						$(".background").hide()
					},
				},
			})
		}

		//获取就诊人信息列表
		function getInquiryPatientInfoList() {
			newAjaxPost("/h5/patientInfo/getInquiryPatientInfoList", {}, (json) => {
				patientInfoList = json.data.list;
				// console.log(patientInfoList);
				let swiperSlide = ""
				patientInfoList.forEach((ele, index) => {
					swiperSlide +=
						`<div class="swiper-slide" >
							<div><span style="overflow:hidden;text-overflow: ellipsis">${ele.patientName}</span><img src="../res/images/edit.png" alt="" onclick="changeInfo(${ele.id})"></div>
							<div style="font-size: 14px;color: #666666;font-weight: 500;">${ele.patientSex == 1?"男":"女"} ${ele.patientAge}岁 ${setPaymentMethod(ele.paymentMethod)}</div>
						</div>`
				});
				$("#banner .swiper-wrapper").html(swiperSlide)
			})
		}

		//选择手机中图片
		function chooseImage() {
			document.querySelectorAll("#img-upload").forEach((item, index) => {
				item.addEventListener("change", function (e) {
					let index = $(this).attr("index")
					var url = window.URL || window.webkitURL || window.mozURL,
						file = e.target.files[0];
					var value = e.target.value; //value是本地的图片路径

					var formData = new FormData();

					//获取当前时间戳加上获取的文件后缀 为文件名
					var filename = new Date().getTime() + getSuffix(value);

					// //注意formData里append添加的键的大小写
					formData.append('key', ossdata.dir + filename); //存储在oss的文件路径
					formData.append('OSSAccessKeyId', ossdata.accessid); //accessKeyId
					formData.append('policy', ossdata.policy); //policy
					formData.append('Signature', ossdata.signature); //签名
					formData.append('callback', ossdata.callback); //签名
					//如果是base64文件，那么直接把base64字符串转成blob对象进行上传就可以了
					formData.append("file", file);
					formData.append('success_action_status', 200); //成功后返回的操作码
					$.ajax({
						type: 'POST',
						data: formData,
						processData: false, //这里默认为true,必须手动改为false
						contentType: false, //这里必须手动改为false,避免出现解析错误
						cache: false, //缓存必须改为false,保证每次都能读取最新数据
						url: ossdata.host,
						success: function (res) {
							if (res.code == 1) { //上传成功
								msgInfo('图片上传成功', 1000);
								Picdata = res.data
								picDataList.push(Picdata.filename)
								picNum++;
								console.log(picNum);
								createUpdateImage()
								picDataList.forEach((item, index) => {
									$(".showImage").eq(index).attr('src', item);
									$(".showImage").eq(index).show()
									$(".deleteImage").eq(index).show()
									$(".chooseImage").eq(index).hide()
								})
								chooseImage()
								console.log(picDataList);
							}
						},
						error: function (error) {
							console.log(error); //文件上传失败打印错误信息
						}
					})

				})
			})
		}

		// getSuffix() 方法用于获取文件名的后缀
		var getSuffix = function (fileName) {
			var pos = fileName.lastIndexOf(".");
			var suffix = '';
			if (pos != -1) {
				suffix = fileName.substring(pos);
			}
			return suffix;
		};

		//渲染图片上传模块函数
		function createUpdateImage() {
			let html = ""
			for (let i = 0; i < picNum; i++) {
				if (i == 8) {

				} else {
					html += `<div class="imageItem">
							<div class="chooseImage">
								<input type="file" accept="image/*" id="img-upload" index="${i}">
								<img src="../res/images/icon_camera@2x.png" alt="">
								<p>上传</p>
							</div>
							<img src="" alt="" class="showImage" onclick="showImage(this)" index="${i}">
							<img src="../res/images/icon_delete@2x.png" alt="" class="deleteImage" index="${i}">
						</div>`
					$(".imageWrappar").html(html)
				}
			}
			//删除图片
			deleteImage()
		}

		//删除对应的选择图片
		function deleteImage() {
			document.querySelectorAll(".deleteImage").forEach((item, index) => {
				item.addEventListener("click", function (e) {
					console.log(1);
					picDataList.splice(index, 1)
					console.log(picDataList);
					picNum--;
					createUpdateImage()
					picDataList.forEach((item, index) => {
						$(".showImage").eq(index).attr('src', item);
						$(".showImage").eq(index).show()
						$(".deleteImage").eq(index).show()
						$(".chooseImage").eq(index).hide()
					})
					chooseImage()
				})
			})
		}
		//点击显示图片
		function showImage(e) {
			let index = $(e).attr("index")
			$(".showPic").show()
			$(".background").show()
			let html = ''
			picDataList.forEach((item, index) => {
				html += `<div class="swiper-slide"><img src="${item}" /></div>`
			})
			$(".showPic .swiper-wrapper").html(html)
			showPic.slideTo(index, 300, false);
		}
		//修改就诊人信息
		function changeInfo(id) {
			goPage(`patient_info.htm?id=${id}`)
		}

		//添加就诊人信息
		function addInfo() {
			goPage(`patient_info.htm`)
		}

		//判断就诊人是否存在就诊卡号
		function queryMedicalCardByinquiryPatientId(id) {
			let params = { id }

			newAjaxPost("/h5/inquiryPatientInfo/queryMedicalCardByinquiryPatientId", params, (res) => {
				if ( res.data.healthCardNo ){
					// 有卡号 进入发起问诊
					doSavePat();
				}else{
					// 没有卡号 再次确认就诊人信息
					$("#tip-mask").show()
				}
			})
		}

		function checkOk() {
			$('#tip-mask').hide();
			// $(".background2").hide();
			doSavePat()
		}

		//结束问诊
		function endInquiryBtn() {
			let params = {
				"doctorId": parseInt(getQst('doctor_id')),
				"userId": parseInt(getQst("user_id"))
			}
			newAjaxPost("/h5/inquiryPatientInfo/endInquiry", params, (res) => {
				msgInfo(res.msg, 1000);
				$(".backgrounds").hide()
				$(".endInquiryInfo").hide()

				if (TESTING && res.code == 1) {
					setTimeout(() => {
						doSavePat()
					}, 1000);
				}
			})
		}

		$(function () {
			h5_token = getQst("h5_token");
			user_id = parseInt(getQst("user_id"));
			user_type = getQst("user_type");
			doctor_name = getQst("doctor_name")
			params = {
				'h5Token': h5_token,
				'id': user_id,
				'type': user_type
			}
			localStorage.setItem("DSXBuserJson", jsonToStr(params));
			iosGoBrowser();
			newOssPolicy()

			$('#div_allergy_details').hide();
			$('#div_medical_history').hide();

			//获取就诊人信息列表
			getInquiryPatientInfoList()
			//渲染图片上传模块
			createUpdateImage()
			//选择图片
			chooseImage()
			//swiper
			swiper()

			//立即咨询
			$('#btnInquiry').click(function () {
				// console.log(patientInfoList[num])

				// 非his 直接进入发起问诊
				if(!isHis){
					doSavePat();
					return ;
				}

				// his	判断就诊人是否有his就诊卡
				if (num == -1) {
					msgInfo('请先选择就诊人');
				}else{
					queryMedicalCardByinquiryPatientId(patientInfoList[num].id)
				}
			});

			// 退款
			$("#btnRefund").click(function () {
				$.confirm('是否确认退款', function () {
					var params = {
						"doctorId": getQst('doctor_id'),
						"isFrozen": 0
					}
					newAjaxPost("/h5/wxpay/refund", params, newRefeeOk);
				}, function () {
					// 取消
				})
			})
			function newRefeeOk(jsonInfo) {
				if (jsonInfo.code == 1) {
					// msgInfo('退费成功，请重新选择医生问诊');
					setTimeout(function () {
						msgInfo('退款成功')
						goPage('inquiry_doctor_index.htm')
					}, 1000);
				}

			}

			//返回上页
			// $('#btnBack').on("click", function () {
			// 	goPageNo(-1);
			// });

			$('.btn').click(function () {
				if (index == $(this).attr("id")) {
					$(this).toggleClass('active')
				} else {
					index = $(this).attr("id")
					$(this).siblings('div').removeClass('active')
					$(this).toggleClass('active')
				}

			})

			//选择时间
			$("#inquiryTime").datetimePicker({
				title: '首诊时间',
				// min: getThatDay(-182),
				max: getThatDay(),
			});

			// 解决ios返回页面不刷新
			window.onpageshow = function () {
				getInquiryPatientInfoList()
			}

			// 强制阅读协议
			$ ("#weuiAgree").on('click', function (e) {
				if($(this).is(':checked')){
					e.preventDefault()
					showNewAgreement(0)
				}
			})
		});

		function getThatDay(days = 0) {
			let time = new Date().getTime() + 1000 * 60 * 60 * 24 * days,
				thatDay = new Date(time).toLocaleDateString(time),
				dayArr = thatDay.split('/'),
				year = dayArr[0],
				month = dayArr[1],
				date = dayArr[2]
			
			month = month < 10 ? ('0' + month) : month
			date = date < 10 ? ('0' + date) : date

			console.log(`${year}-${month}-${date}`, thatDay)

			return `${year}-${month}-${date}`
		}

		function func() {
			return false;
		}

		// 就诊人列表中显示付费类型
		function setPaymentMethod(type) {
			return type === 2 ? '医保付费' : '自费'
		}

		// 强制阅读协议弹窗=========================\
		function showNewAgreement() {
			myPager.show()
		}

		$(function() {

		// class Pager 
		myPager = {
			pageValue : 0,	//第几页
			pageSize: 0,		//总页数 - 1
			idList : agreements.idList,	//id参数们
			title : $("#newAgreementTitle"),			//页面中显示协议标题的标签
			content : $("#newArgeementContent"),			//页面中显示协议内容的标签
			preBtn : $("#prePage"),			//页面中 上一页按钮
			nextBtn : $("#nextPage"),			//页面中 下一页
			endBtn : $("#finishedRead"),			//页面中 完成
			data: [],		//Array<Object> {id:接口的id参数, title:缓存协议标题, content:缓存协议内容}

			// constructor(obj) {
			// 	this.data = obj.idList.map(item => ({id: item}))
			// 	this.title = obj.title
			// 	this.content = obj.content
			// 	this.preBtn = obj.pre
			// 	this.nextBtn = obj.next
			// 	this.endBtn = obj.end

			// 	this.init()
			// },
			
			get page() {
				return this.pageValue
			},

			set page(val) {
				this.pageValue = val
				this.pageChange()
			},
			
			init() {	//初始化
				this.preBtn.on('click', this.prePage.bind(this))
				this.nextBtn.on('click', this.nextPage.bind(this))
				this.endBtn.on('click', this.finishRead.bind(this))

				if(isChengDu){	//仅成都显示精麻药协议
					this.idList.push(9)
				}
				
				this.pageSize = this.idList.length - 1

				this.data = this.idList.map(id => ({id}))

				this.page = 0

				this.preLode()
			},
			
			show() {
				$("#mustKnow").popup()

				this.page = 0
			},

			prePage() {	//上一页
				this.page--
			},

			nextPage() {	//下一页
				this.page++
			},

			finishRead() {	//完成
				$(".close-popup-btn").click()
				$("#weuiAgree").prop('checked', true)
			},

			pageChange() {	//页的值改变
				this.setBtnState()
				this.getAgreement()
			},

			setBtnState() {	//设置按钮显示状态
				if(this.pageSize === 0){	//只有一项协议
					this.endBtn.show().siblings().hide()
					return
				}

				if (this.page == 0) {	//第一页
					this.nextBtn.show().siblings().hide()
				}
				else if(this.page == this.pageSize){	//最后一页
					this.nextBtn.hide().siblings().show()
				}
				else{
					this.endBtn.hide().siblings().show()
				}
			},

			getAgreement() {	//获取协议
				let data = this.data[this.page]	//根据页值获取对象

				if(data.title && data.content){	//有缓存的协议 不重复请求
					this.cacheRender()
					
				}else{	//没有缓存 获取
					const params = {
						id: this.data[this.page].id
					}
					newAjaxPost("/h5/utilInitData/getAgreement", params, this.render.bind(this))
				}
			},

			cacheRender() {	//从缓存渲染
				let {title, content} = this.data[this.page]
				
				this.title.text(title)
				this.content.html(content)
			},

			render(res) {	//请求后渲染
				let title = res.data.initName,
					content = res.data.initKey.replace(/。/g, '。<br>')
				
				this.data[this.page].title = title
				this.data[this.page].content = content
				
				this.title.text(title)
				this.content.html(content)
			},

			preLode() {	//预加载 动态获取协议标题
				while (this.page < this.pageSize) {
					this.page++
				}

				setTimeout(() => {
					this.data.forEach((item, ind) => {
						agreements.titleList[ind] = `《${item.title}》`
					})
					$("#agreementTitles").text(agreements.titleList.join(','))
				}, 1);
			}
		}
		myPager.init()

		// 	myPager = new Pager({	//实例化分页器
		// 		idList: [2, 6, 9],
		// 		title: $("#newAgreementTitle"),
		// 		content: $("#newArgeementContent"),
		// 		pre: $("#prePage"),
		// 		next: $("#nextPage"),
		// 		end: $("#finishedRead"),
		// 	})
		})
		// 强制阅读协议弹窗=========================/
	</script>
	<style>
		.weixin-tip {
			display: none;
			position: fixed;
			left: 0;
			top: 0;
			bottom: 0;
			margin: 0;
			padding: 0;
			background: rgba(0, 0, 0, 0.8);
			filter: alpha(opacity=80);
			z-index: 99;
		}

		.weixin-tip p {
			text-align: center;
			margin-top: 10%;
			padding: 0 5%;
		}

		.weixin-tip img {
			max-width: 100%;
			height: auto;
		}

		.weui-header-fixed-top {
			position: fixed;
			left: 0;
			top: 0;
			right: 0;
			z-index: 9;
			background: #F6F6F9
		}

		.tbList th {
			text-align: center
		}

		.keybroad-province {
			background: #F8F9FE;
			position: fixed;
			bottom: 0;
			left: 0;
			right: 0;
			z-index: 111;
			clear: both;
			overflow: hidden;
			height: 100%;
			border-top: 2px solid #999999;
		}

		.keybroad-province .top-line {
			height: 40px;
			line-height: 40px;
			background: #FFFFFF;
			width: 100%;
			clear: both;
			display: block;
			text-align: center;
			font-size: 18px;
		}

		.keybroad-province .btn-packup {
			position: absolute;
			padding-left: 10px;
			;
			font-size: 16px;
			height: 40px;
			line-height: 40px;
		}

		.keybroad-province .kaybroad-value {
			float: left;
			width: 11.11%;
			border-bottom: 1px solid #EEE;
			border-right: 1px solid #EEE;
			margin-left: -1px;
			text-align: center;
			padding: 0.3125rem 0;
			font-size: 18px;
			display: inline-block;
			position: relative;
		}

		.keybroad-province .kaybroad-value.chosen {
			background: #09BB07;
			color: #FFF !important;
		}

		.font-link {
			color: #576B95 !important;
		}

		a {
			text-decoration: none;
			color: #0081FF;
		}

		.font-black {
			color: #000 !important;
		}

		.tbList tr:hover {
			background-color: #EEEEEE;
		}

		.sel {
			width: 30%;
			border-radius: 10px;
			background: #1189FF;
			font-size: 13px;
			line-height: 29px;
			height: 29px;
			margin-top: 5px;
			display: inline-block;
			float: right;
			border: 0;
			color: white;
		}

		.weui-select {
			z-index: 0;
			padding-left: 0px;
		}

		.weui-footer_fixed-bottom {
			bottom: 0px;
			border-top: 2px solid #ddd;
		}

		.weui-form-checkbox[type="radio"]:checked+label .weui-icon-radio {
			background-color: #FCA92B;
			border: 1px solid #1189ff;
		}

		.weui-icon-radio {
			vertical-align: sub;
		}

		.weui-form-text {
			font-size: 15px;
		}

		.weui-search-bar__label {
			line-height: 36px;
		}

		.weui-search-bar {
			width: 100%
		}

		.weui-search-bar__form {
			height: 40;
		}

		.weui-search-bar__box .weui-search-bar__input {
			height: 32px;
		}

		.weui-search-bar__cancel-btn {
			width: 80px;
			line-height: 40px;
			height: 40px;
		}

		.weui-cell {
			display: block;
			padding: 0 10px;
		}

		.weui-label {
			font-weight: unset;
			display: block;
			height: 40px;
			line-height: 40px;
			width: 110px;
		}

		.weui-cell__bd {
			height: 40px;
			line-height: 38px;
			font-size: 15px;
		}

		.weui-form-li {
			display: contents;
		}

		strong {
			display: block;
		}

		.weui-search-bar__box .weui-icon-clear {
			right: 24px;
		}

		.weui-search-btn {
			background: #1189ff;
			text-align: center;
			color: #ffffff;
			border-radius: 10px;
			position: absolute;
			right: 0;
			top: 0;
			white-space: nowrap;
			width: 80px;
			line-height: 40px;
			height: 40px;
		}

		.picker-items-col-center {
			width: 100%;
		}

		#weuiAgree {
			width: 16px;
			height: 16px;
		}

		.top {
			font-size: 14px;
			padding: 10px;
			display: block;
			text-align: center;
		}

		.top span {
			margin: 0 10px;
		}

		.tip {
			background-color: #fff;
			width: 95%;
			margin: 0px 2.5% 10px;
			border-radius: 10px;
			overflow: hidden;
		}

		.tip div:nth-child(1) {
			font-size: 16px;
			font-family: Source Han Sans CN;
			font-weight: bold;
			color: #222222;
			margin: 8px 0;
			text-align: center;
			word-spacing: 2px;
		}

		.tip div:nth-child(2) {
			font-size: 13px;
			font-family: PingFang SC;
			font-weight: 500;
			color: #666666;
			margin: 8px 0;
			text-align: center;
		}

		.chooseUser {
			display: flex;
			font-size: 14px;
			font-family: PingFang SC;
			font-weight: bold;
			color: #222222;
			padding: 0 15px;
			padding-top: 15px;
			width: 100%;
		}

		.chooseUser p:nth-child(1) {
			width: 80%;
		}

		#banner{
			overflow: hidden;
		}
		
		#banner .swiper-container {
			/* width: 100%; */
			padding: 10px 5px;
		}

		#banner .swiper-slide {
			width: 35%;
			padding: 15px;
			border: 1px solid #F1F1F3;
			margin: 5px 0px;
		}

		.active {
			border: 1px solid #03A6FF !important;
			background: #F5FBFF !important;
		}

		#banner .swiper-slide img {
			width: 13px;
			height: 13px;
		}

		#banner .swiper-slide div {
			display: flex;
			justify-content: space-between;
			font-size: 17px;
			font-weight: bold;
			color: #353535;
			font-family: PingFang-SC-Medium;
			align-items: center;
			margin: 5px 0;
		}

		.uploadPhotos {
			overflow: hidden;
			margin-top: 0;
			margin-bottom: 0;
		}

		.uploadPhotos>div {
			margin: 10px 0;
		}

		.uploadPhotos .upload-title {
			font-size: 15px;
			font-family: PingFang SC;
			font-weight: bold;
			color: #222222;
		}

		.img-tips, .inquiry-tips {
			font-size: 13px;
			font-family: PingFang SC;
			font-weight: 400;
			color: #666666;
		}

		.first-inquiry, .first-inquiry-time {
			padding: 1px;
			font-size: 15px;
			color: #666;
			display: flex;
			align-items: center;
		}

		#inquiryTime, #firstInquiryHos{
			flex-grow: 1;
			border: 1px solid #666;
			margin-left: 10px;
			padding: 5px;
			border-radius: 4px;
		}

		.chooseImage{
			text-align: center;
		}

		.imageWrappar {
			/* width: 100%; */
			display: flex;
			flex-wrap: wrap;
			justify-content: left;
			align-items: center;
		}

		.imageWrappar .imageItem {
			margin: 5px !important;
			width: 70px;
			height: 70px;
			background: rgba(3, 166, 255, 0.06);
			border-radius: 10px;
			display: flex;
			flex-wrap: wrap;
			justify-content: center;
			align-items: center;
			position: relative;
		}

		.imageWrappar .imageItem img {
			width: 25px;
			height: 23px;
			margin-top: 10px;
		}

		.imageWrappar .imageItem p {
			width: 100%;
			font-weight: 500;
			color: #03A6FF !important;
			text-align: center;
		}

		.imageWrappar .imageItem #img-upload {
			position: absolute;
			top: 0;
			left: 0;
			width: 70px;
			height: 70px;
			background: rgba(3, 166, 255, 0.06);
			opacity: 0;
		}

		.imageWrappar .imageItem .showImage {
			width: 100%;
			height: 100%;
			display: none;
			margin: 0;
		}

		.imageWrappar .imageItem .deleteImage {
			width: 25px;
			width: 25px;
			display: none;
			margin: 0;
			position: absolute;
			top: -12.5px;
			right: -12.5px;
		}

		.background {
			width: 100%;
			height: 100vh;
			position: fixed;
			top: 0;
			background: rgba(0, 0, 0);
			z-index: 99;
		}

		.showPic {
			width: 100%;
			background-color: rgba(0, 0, 0);
			;
			position: fixed;
			left: 50%;
			top: 50%;
			transform: translate(-50%, -50%);
			z-index: 100;
		}

		.weui-label {
			font-size: 15px;
			width: 100px;
		}

		.background2 {
			width: 100%;
			height: 100vh;
			background-color: rgba(0, 0, 0, 0.3);
			;
			position: fixed;
			left: 50%;
			top: 50%;
			transform: translate(-50%, -50%);
			z-index: 100;
		}

		.backgrounds{
			position: fixed;
			top: 0;
			bottom: 0;
			left: 0;
			right: 0;
			background-color: #0003;
			z-index: 99;
		}

		#tip-mask{
			position: absolute;
			top: 0;
			bottom: 0;
			left: 0;
			right: 0;
			background-color: #0006;
			z-index: 9;
			display: none;
		}
		
		.tipShow {
			position: fixed;
			left: 50%;
			top: 50%;
			transform: translate(-50%, -50%);
			z-index: 105;
			width: 80%;
			background-color: #fff;
			font-size: 15px;
			border-radius: 8px;
		}

		.tipShow .tipTitle {
			display: flex;
			justify-content: space-between;
			padding: 10px;
		}

		.tipShow .tipTitle div:last-child {
			color: #03A6FF;
		}

		.tipShow .tipMessage {
			margin: 30px 0;
			text-align: center;
		}

		.tipShow .tipBtns {
			display: flex;
			justify-content: space-around;
			margin-bottom: 15px;
		}

		.tipShow .tipBtns div {
			padding: 7px 20px;
			border-radius: 6px;
			border: 1px solid #999999;
		}

		.tipShow .tipBtns div:last-child {
			background-color: #03A6FF;
			border: 1px solid #03A6FF;
			color: #fff;
		}

		.endInquiryInfo {
			width: 80%;
			background-color: #fff;
			position: fixed;
			left: 50%;
			top: 50%;
			transform: translate(-50%, -60%);
			z-index: 100;
			padding: 10px;
			font-size: 14px;
			border-radius: 8px;
		}

		.endInquiryInfo div {
			margin: 10px 0;
			text-align: center;
		}

		.endInquiryInfo .endInquiryBtn {
			margin: 20px auto;
			width: 30%;
			height: 30px;
			line-height: 30px;
			text-align: center;
			background-color: #03A6FF;
			border-radius: 8px;
			color: #fff;
		}

		.agreement-top{
			background: #fff;
			position: sticky;
			position: -webkit-sticky;
			top: 0;
		}
		.agreement-body{
			height: 100vh;
			display: flex;
			flex-direction: column;
		}
		/* 初始隐藏《精麻药》 */
		#controlledSubstance{
			display: none;
		}

		.close-popup-btn{
			position: absolute;
			right: 10px;
			top: 5px;
			bottom: 5px;
			z-index: -1;
			visibility: hidden;
		}
		.must-know-body{
			flex-grow: 1;
		}
		.must-know-bottom{
			position: sticky;
			position: -webkit-sticky;
			bottom: 0;
			left: 0;
			right: 0;
			padding: 10px 0;
			min-height: 50px;
			background-color: #fff;
			display: flex;
			align-items: center;
			justify-content: space-evenly;
		}
		#prePage, #nextPage, #finishedRead{
			margin: 0;
			padding: 5px 40px;
		}
		#nextPage, #finishedRead{
			background-color: #0081FF;
			color: #fff;
		}

		.weui-btn{
			border: 1px solid #0003;
		}
		.weui-btn::after{
			display: none;
		}
	</style>
</head>

<body ontouchstart>
	<div class="weixin-tip">
		<p>
			<img src="../res/images/live_weixin.png" alt="浏览器打开" />
		</p>
	</div>
	<div class="weui-header-fixed-top">
		<div class="weui-header weui-btn_primary">
			<div class="weui-header-left"><a id="btnBack" class="icon icon-109" onclick="history.back()"> </a></div>
			<div class="weui-header-title">发起问诊</div>
			<div class="weui-header-right"></div>
		</div>
	</div>
	<div class="weui-cells weui-cells_form" style="margin-top:45px">
		<div class="top"><span>选择患者</span><span>></span><span>发起问诊</span><span>></span><span>加入聊天室</span></div>
		<div class="tip">
			<div>请选择患者信息并上传相关资料</div>
			<div>以便医生给出更准确的治疗，信息仅医生可见</div>
		</div>
		<!-- 问诊方式选择 -->
		<div class="weui-cell">
			<div class="weui-cell-list" id="banner">
				<div class="chooseUser">
					<p>请选择就诊人<span style="color: red;"> *</span></p>
					<p onclick="addInfo()"><span style="color: #03A6FF;">+</span>添加</p>
				</div>
				<div class="swiper-container">
					<div class="swiper-wrapper">
					</div>
				</div>
			</div>

			<div class="weui-cell uploadPhotos">
				<div class="upload-title">上传病历资料<span style="color: red;"> *</span></div>

				<div class="inquiry-tips">
					请提供初诊相关资料，需明确诊断，患者信息，医院名称等信息。
				</div>

				<div class="first-inquiry">
					<label for="firstInquiryHos">初诊医院</label>
					<input type="text" id="firstInquiryHos" placeholder="请输入初诊医院名称">
				</div>

				<div class="first-inquiry-time">
					<label for="inquiryTime">初诊时间</label>
					<input id="inquiryTime" type="text" value="" placeholder="请选择初诊时间 >">
				</div>
				
				<div class="img-tips">
					<!-- 资料（至少上传两张，最多可上传8张)<br>
					①病历图片需包含初诊医院名称、初诊时间<br>
					②需上传就诊人手持身份证的图片 -->
					请提供初诊相关资料，需明确诊断，患者信息，医院名称等信息。至少上传一张，最多可上传8张
				</div>
				<div class="imageWrappar">

				</div>
			</div>

			<div class="weui-cell" style="padding: 10px;font-size: 14px;">
				<input id="weuiAgree" name="weuiAgree" type="checkbox">
				<em class="checkbox"></em>
				<label class="text" style="padding-left:3px;" for="weuiAgree">我已详细阅读并同意</label>
				<span onclick="showNewAgreement();">
					<a href="javascript:;" id="agreementTitles"></a>
				</span>
			</div>
		</div>
		<div class="keybroad-province hide" id="province">
			<!-- 问诊历史列表 -->
			<a href="javascript:void(0)" onclick="$('#province').hide()" class="btn-packup font-link icon icon-109"></a>
			<div class="top-line">搜索手机号</div>
			<div id="userList" class="weui-cells" style="overflow: auto;height: 95%;"></div>
		</div>
		<a class="weui-btn weui-btn_mini bg-blue f-white" href="javascript:;" id="btnInquiry"
			style="font-size: 17px; margin: 0 5%; width: 90%;">发起问诊
		</a>
		<a class="weui-btn weui-btn_mini" href="javascript:;" id="btnRefund"
			style="font-size: 17px; margin: 0 5%; width: 90%; color: #333;">申请退款
		</a>

		
		<!--用户协议-->
		<div id="divAgreeInfo" class='weui-popup__container'>
			<div class="weui-popup__overlay"></div>
			<div class="weui-popup__modal">
				<div class="weui-cells weui-cells_form agreement-body">
					<div class="agreement-top">
						<div class="weui-cell__bd" style="text-align: center;"><span id="argeeTitle"></span></div>
						<div class="weui-cell__ft" style="position: absolute; right: 5px; top: 5px;">
							<a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_primary close-popup">关闭</a>
						</div>
					</div>
					<div class="weui-cell" style="overflow: auto;">
						<div class="argeeContent">
							<span id="argeeContent"></span>
						</div>
					</div>
				</div>
			</div>
		</div>

		<!-- 不可跳过的用户协议 -->
		<div id="mustKnow" class='weui-popup__container'>
			<div class="weui-popup__overlay"></div>
			<div class="weui-popup__modal">
				<div class="weui-cells weui-cells_form agreement-body">
					<div class="agreement-top">
						<div class="weui-cell__bd" style="text-align: center;">
							<span id="newAgreementTitle">协议标题</span>
							<a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_primary close-popup close-popup-btn">关闭</a>
						</div>
					</div>

					<div class="weui-cell must-know-body" style="overflow: auto;">
						<div class="argeeContent">
							<span id="newArgeementContent">
								协议内容
							</span>
						</div>
					</div>

					<div class="must-know-bottom">
						<div class="weui-btn weui-btn_mini weui-btn_primary" id="prePage">上一页</div>
						<div class="weui-btn weui-btn_mini weui-btn_primary" id="nextPage">下一页</div>
						<div class="weui-btn weui-btn_mini weui-btn_primary" id="finishedRead">完成</div>
					</div>
				</div>
			</div>
		</div>
		
		<div class="background" onclick="$('.showPic').hide();$(this).hide()" style="display: none;"></div>
		<div class="background2" onclick="$('.tipShow').hide();$(this).hide()" style="display: none;"></div>
		<div class="endInquiryInfo" style="display: none;">
			<div>提示</div>
			<div>你有一个问诊还未结束，请先结束问诊</div>
			<div class="endInquiryBtn" onclick="endInquiryBtn()">确定</div>
		</div>
		<div class="backgrounds" onclick="$('.endInquiryInfo').hide();$(this).hide()" style="display: none;"></div>
		<div class="showPic" style="display: none;">
			<div class="swiper-container">
				<div class="swiper-wrapper">

				</div>
			</div>
		</div>
	</div>
	<div id="tip-mask">
		<div class="tipShow">
			<div class="tipTitle">
				<div>温馨提示</div>
				<div onclick="$('#tip-mask').hide()">关闭</div>
			</div>
			<div class="tipMessage">
				确认就诊人信息无误?
			</div>
			<div class="tipBtns">
				<div class="tipLightBtn" onclick="goPage(`patient_info.htm?id=${patientInfoList[num].id}`)">查看信息
				</div>
				<div class="tipRightBtn" onclick="checkOk()">确认无误</div>
			</div>
		</div>
	</div>
</body>

</html>